import config from '@/config'
import storage from '@/utils/storage'
import constant from '@/utils/constant'
import {
	getPeriod,
	getSubject,
	getArea,
	getTeacher
} from '@/api/teach'
const baseUrl = config.baseUrl

const teach = {
	state: {
		period: [],
		subject: [],
		area: [],
		sign: ""
	},

	mutations: {
		SET_PERIOD: (state, params) => {
			state.period = params
		},
		SET_SUBJECT: (state, params) => {
			state.subject = params
		},
		SET_AREA: (state, params) => {
			state.area = params
		},
		SET_SIGN: (state, params) => {
			state.sign = params
		}
	},

	actions: {
		//获取学段
		GetPeriodData({
			commit,
			state
		}) {
			return new Promise((resolve, reject) => {
				getPeriod().then(res => {
					let period = [];
					res.periods.forEach(item => {
						period.push({
							value: item.code,
							grade: item.grade,
							text: item.name
						})
					})
					commit('SET_PERIOD', period);
					resolve();
				}).catch(error => {
					reject(error)
				})
			})
		},

		//获取学科
		getSubjectData({
			commit,
			state
		}) {
			return new Promise((resolve, reject) => {
				getSubject().then(res => {
					let subject = [];
					res.subjects.forEach(item => {
						subject.push({
							value: item.id,
							text: item.name
						})
					})
					commit('SET_SUBJECT', subject);
					resolve();
				}).catch(error => {
					reject(error)
				})
			})
		},
		//获取区县
		getAreaData({
			commit,
			state
		}) {
			return new Promise((resolve, reject) => {
				getArea().then(res => {
					let area = [];
					res.areas.forEach(item => {
						// let chide=[];
						// getTeacher({deviceId:'88888888',area_code:item.code}).then(res=>{
						//     res.users.forEach(key=>{
						//         chide.push({value:key.id,text:key.name})
						//     })
						// })
						area.push({
							value: item.code,
							text: item.name
						});
					})

					commit('SET_AREA', area);
					resolve();
				}).catch(error => {
					reject(error)
				})
			})
		},
	}
}

export default teach